package com.epoint.pjq.core;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.widget.EditText;

public class StringHelp {
	public static String OschinaStyle = "<style>#oschina_title {color: #000000; margin-bottom: 6px;font-weight:bold;font-size:18px;}#oschina_title img{vertical-align:middle;margin-right:6px;}#oschina_title a{color:#0D6DA8;}#oschina_outline {color: #707070; font-size:12px;}#oschina_outline a{color:#0D6DA8;}#epoint_sender{color:#000033; font-size:12px;}#oschina_software{color:#808080;font-size:12px}#oschina_body img {max-width: 300px;}#oschina_body{font-size:16px;max-width:300px;line-height:24px;} #oschina_body table{max-width:300px;}#oschina_body pre {font-size:9pt;font-family:Courier New,Arial;border:1px solid #ddd;border-left:5px solid #6CE26C;background:#f6f6f6;padding:5px;}</style>";
	public static String HR_style1 = "<hr style=\"height:1px\" color=Silver>";
	public static String HR_style2 = "<hr style=\"border-top: 2px dashed; border-bottom: 2px dashed; height: 2px\" color=black>";

	public static boolean isLength0(String s) {
		if (s.trim().length() == 0) {
			return true;
		}
		return false;
	}

	public static String XMLSwitchedOrigion(String oldstring) {
		oldstring = oldstring.replaceAll("&amp;", "&");
		oldstring = oldstring.replaceAll("&lt;", "<");
		oldstring = oldstring.replaceAll("&gt;", ">");
		oldstring = oldstring.replaceAll("&apos;", "'");
		oldstring = oldstring.replaceAll("&quot;", "\"");
		return oldstring;
	}

	public static String XMLSwitched(String oldstring) {
		oldstring = oldstring.replaceAll("&", "&amp;");
		oldstring = oldstring.replaceAll("<", "&lt;");
		oldstring = oldstring.replaceAll(">", "&gt;");
		oldstring = oldstring.replaceAll("'", "&apos;");
		oldstring = oldstring.replaceAll("\"", "&quot;");
		return oldstring;
	}

	public static String getXMLAtt(String bs, String att) {
		String result = "";
		try {
			String head = "<" + att + ">";
			String tail = "</" + att + ">";
			result = bs.substring(bs.indexOf(head) + head.length(),
					bs.indexOf(tail));
		} catch (Exception e) {
			e.printStackTrace();
			return "";
		}
		return result;
	}

	public static String getXMLAttOut(String bs, String att) {
		String bs1 = getXMLAtt(bs, att);
		return "<" + att + ">" + bs1 + "</" + att + ">";
	}

	public static String getAttOut(String bs, String att) {
		String s = "";
		try {
			s = bs.substring(bs.indexOf("<" + att + ">"),
					bs.indexOf("</" + att + ">") + ("</" + att + ">").length());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return s;
	}

	public static String get2AttMid(String bs, String q, String h) {
		return bs.substring(bs.indexOf(q) + q.length(), bs.indexOf(h));
	}

	public static String[] dealChooseListToString(List<Map<String, String>> clst) {
		String snname = "";
		String sguid = "";
		int size = clst.size();
		if (size > 0) {
			for (int i = 0; i < size; i++) {
				if (i < size - 1) {
					snname = snname + (String) ((Map) clst.get(i)).get("name")
							+ ";";
					sguid = sguid + (String) ((Map) clst.get(i)).get("guid")
							+ ";";
				} else if (i == size - 1) {
					snname = snname + (String) ((Map) clst.get(i)).get("name");
					sguid = sguid + (String) ((Map) clst.get(i)).get("guid");
				}
			}
		}
		String[] info = new String[2];
		info[0] = snname;
		info[1] = sguid;
		return info;
	}

	@SuppressWarnings("rawtypes")
	public static List<Map<String, String>> String2List(String names,
			String guids) {
		List<Map<String, String>> list = new ArrayList();
		if ((names == null) || (guids == null) || ("".equals(names))
				|| ("".equals(guids))) {
			return new ArrayList();
		}
		String[] s_name = names.split(";");
		String[] s_guid = guids.split(";");
		for (int i = 0; i < s_name.length; i++) {
			Map<String, String> map = new HashMap();
			map.put("name", s_name[i]);
			map.put("guid", s_guid[i]);
			list.add(map);
		}
		return list;
	}

	public static boolean isEditTextBlank(EditText et) {
		if (et.getText().toString().trim().length() == 0) {
			return true;
		}
		return false;
	}

	public static boolean isEqualBlank(String s) {
		s = s == null ? "" : s;
		if (s.equals("")) {
			return true;
		}
		return false;
	}

	public static String cutLastSymbol(String s, String Symbol) {
		if (s.endsWith(Symbol)) {
			return s.substring(0, s.length() - 1);
		}
		return s;
	}

	public static int versionToInteger(String versionstr) {
		try {
			String[] ss = versionstr.split("\\.");
			String sv = "";
			String[] arrayOfString1;
			int j = (arrayOfString1 = ss).length;
			for (int i = 0; i < j; i++) {
				String s = arrayOfString1[i];
				sv = sv + s;
			}
			return Integer.parseInt(sv);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 0;
	}
}
